<?php
/**
 * Created by PhpStorm.
 * User: vanity
 * Date: 2018/1/2
 * Time: 16:32
 */
namespace Admin\Model;
use Think\Model\RelationModel;
class PermissionsModel extends RelationModel
{
    protected $tableName = 'permissions';
    protected $patchValidate = true;
    protected $_validate = array(
        array('name','require','用户名不能为空',0),
        array('label','require','用户名不能为空',0),
        array('name','require','权限路径已经存在！',0,'unique',1),
        array('label','require','权限名称已经存在！',0,'unique',1),
        array('cid','number','cid出现错误！',2),
    );
    protected $_auto = array (
        array('created_time','time',1,'function'), // 对update_time字段在添加的时候写入当前时间戳
        array('updated_time','time',2,'function'), // 对update_time字段在更新的时候写入当前时间戳
    );
    protected $_link = array(
        'permission_role'=>array( //权限和权限角色关联表
            'mapping_type'=> self::HAS_MANY,//多（role_id）关联一（permission_id）用 HAS_MANY，一(permission_id)关联多（role_id）用BELONGS_TO
            'foreign_key'=>'permission_id', //permission_role表中的博文permission_id
            'mapping_fields'=>'role_id',
        )
    );
}